﻿using System;
using System.Data;
using System.Data.SqlClient;
using AccessControl.Sida.Common;


namespace AccessControl.Sida.DataAccess
{
	public class ExamReportAccess
	{
		public SidaDS.ExamCardDataTable SelectReportByStudent(String studentCode)
		{
			using (var cn = new SqlConnection(Util.ConnectionString))
			{
				var cmdSelect =
					new SqlCommand("SPExamCard", cn){CommandType=CommandType.StoredProcedure};
				cmdSelect.Parameters.AddWithValue("@stcode", studentCode);
				var examCardDataTable= new SidaDS.ExamCardDataTable();
				try
				{
					cn.Open();
					var reader = cmdSelect.ExecuteReader();
					if (reader != null)
						while (reader.Read())
						{
							var newRow = examCardDataTable.NewExamCardRow();
							newRow.dateexam = reader["dateexam"].ToString();
							newRow.namedars = reader["namedars"].ToString();
							newRow.stcode = reader["stcode"].ToString();
							newRow.name = reader["name"].ToString();
							newRow.namep = reader["namep"].ToString();
							newRow.idd = reader["idd"].ToString();
							newRow.saatexam = reader["saatexam"].ToString();
							newRow.nameresh = reader["nameresh"].ToString();
							newRow.codebayegan = reader["codebayegan"].ToString();
							if (reader["sandal"] != DBNull.Value)
								newRow.sandal = reader["sandal"].ToString();
							newRow.did = reader["did"].ToString();
							if (reader["ExamPlace"] != DBNull.Value)
								newRow.ExamPlace = reader["ExamPlace"].ToString();
							newRow.nameostad = reader["nameostad"].ToString();
							if (reader["stu_pic"] != DBNull.Value)
							newRow.stu_pic = (Byte[])reader["stu_pic"];
							newRow.family = reader["family"].ToString();
							newRow.Term = reader["term"].ToString();
							newRow.Pass= reader["Pass"].ToString();
							
							
							examCardDataTable.AddExamCardRow(newRow);
						}
				}
				finally
				{
					cn.Close();
				}
				return examCardDataTable.Rows.Count != 0 ? examCardDataTable : null;
			}
		}
	}
}
